


<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="阶段名称" prop="postName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入阶段名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

    <el-table v-loading="loading" :data="paperList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="阶段名称" align="center" prop="stageName" />
      <el-table-column label="试卷名称" align="center" prop="paperName" />
      <el-table-column label="考试时长" align="center" prop="totalTime"/>
      <el-table-column label="考试总分" align="center" prop="totalMark"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="startExam(scope.row)"
            v-hasPermi="['store:paper:start']"
          >开始考试</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {listPaper,getPaper, delQues, addPaper, updateQues,getCount } from "@/api/store/paper";
import {delStage, getStage} from "@/api/stage/stagelist";
import axios from "axios";
import {listDetail, listStuDetail} from "@/api/store/detail";

export default {
  name: "Ques",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //试卷Id
      paperId:undefined,
      paperName:undefined,
      totalTime:undefined,
      totalMark:undefined,
      passMark:undefined,
      singleCount:0,
      totalScore:undefined,
      storeOptions:[],
      storeName:undefined,
      storeId:undefined,

      // 总条数
      total: 0,
      // 岗位表格数据
      paperList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paperId:undefined,
        paperName:undefined,
        totalTime:undefined,
        totalMark:undefined,
        passMark:undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        quesName: [
          { required: true, message: "题库名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },

  computed: {
    addtotal() {
      return 100;
    },
  },


  methods: {
    /**开始考试*/
    startExam(row){
      listDetail().then((res)=>{
        this.stuList = res.rows;
        listStuDetail().then((res)=>{
          this.userList = res.rows;
          for (let item of this.stuList){
            for (let item1 of this.userList){
              if (item.userId === item1.userId && row.paperId === item1.paperId){
                return  this.$message("您已完成该考试");
              }
            }
          }
          this.$router.push("/exam/"+row.paperId);

        })

      });

    },

    /** 显示所有 */
    getList() {
      this.loading = true;
      listPaper(this.queryParams).then((response) => {
        this.paperList = response.rows;
        this.total = response.total;
        this.loading = false;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        quesId: undefined,
        storeId:undefined,
        quesName: undefined,
        quesHard:undefined,
        quesType:undefined,
        selContA:'',
        selContB:'',
        selContC:'',
        selContD:'',
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
<style>
.diaolog .el-table .el-table__header-wrapper thead th,
.diaolog .el-table .el-table__fixed-header-wrapper thead th {
  display: none;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
